package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.PhoneModel;
import com.stylefeng.guns.modular.system.service.IPhoneModelService;

/**
 * 手机机型设置控制器
 *
 * @author fengshuonan
 * @Date 2018-12-24 14:17:55
 */
@Controller
@RequestMapping("/phoneModel")
public class PhoneModelController extends BaseController {

    private String PREFIX = "/system/phoneModel/";

    @Autowired
    private IPhoneModelService phoneModelService;

    /**
     * 跳转到手机机型设置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "phoneModel.html";
    }

    /**
     * 跳转到添加手机机型设置
     */
    @RequestMapping("/phoneModel_add")
    public String phoneModelAdd() {
        return PREFIX + "phoneModel_add.html";
    }

    /**
     * 跳转到修改手机机型设置
     */
    @RequestMapping("/phoneModel_update/{phoneModelId}")
    public String phoneModelUpdate(@PathVariable Integer phoneModelId, Model model) {
        PhoneModel phoneModel = phoneModelService.selectById(phoneModelId);
        model.addAttribute("item",phoneModel);
        LogObjectHolder.me().set(phoneModel);
        return PREFIX + "phoneModel_edit.html";
    }

    /**
     * 获取手机机型设置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return phoneModelService.selectList(null);
    }

    /**
     * 新增手机机型设置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(PhoneModel phoneModel) {
        phoneModelService.insert(phoneModel);
        return SUCCESS_TIP;
    }

    /**
     * 删除手机机型设置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer phoneModelId) {
        phoneModelService.deleteById(phoneModelId);
        return SUCCESS_TIP;
    }

    /**
     * 修改手机机型设置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(PhoneModel phoneModel) {
        phoneModelService.updateById(phoneModel);
        return SUCCESS_TIP;
    }

    /**
     * 手机机型设置详情
     */
    @RequestMapping(value = "/detail/{phoneModelId}")
    @ResponseBody
    public Object detail(@PathVariable("phoneModelId") Integer phoneModelId) {
        return phoneModelService.selectById(phoneModelId);
    }
}
